@extends('home.lei.business.index')
@section('r_content')
	<link rel="stylesheet" href="/lei/home/shenqing.css">
	<div style="width:950px;height:100%;float:left;background:white;margin-left:10px;">
		<div style="width:900px;height:40px;background:#ccc;margin-top:10px;">
			<span style="font-size:30px;color:white;">添加菜品</span>
		</div>
		<div style="width:1050px;padding-left:50px;">
			<form class="navbar-form navbar-left" role="search" action="/home/good/{{$data['id']}}" method="post"  enctype="multipart/form-data">
				{{ csrf_field() }}
				<input type="hidden" name="_method" value="PUT">
				  <div class="form-group">
				    	<b class="icon">*</b></label><span>菜品名称：</span><input type="text" name="g_name" value="{{$data['g_name']}}" class="form-control" style="width:300px">
				  </div><br>
				  <div class="form-group">
				    	<b class="icon">*</b></label><span>菜品价格：</span><input type="text" name="g_price" value="{{$data['g_price']}}" class="form-control" style="width:100px"><span>元</span>
				  </div><br>
				  <div class="form-group">
				    	<b class="icon">*</b></label><span>菜品描述：</span><input type="text" name="g_description" value="{{$data['g_description']}}" class="form-control" style="width:400px">
				  </div><br>
				  <div class="form-group">
				    	<div style="float:left;"><b class="icon">*</b></label><span>菜品图片：</span></div>
				    	<div style="border:1px solid #ccc;width:700px;height:142px;float:left;">
				    		<div style="width:200px;float:left;">
				    			原图:<img src="/lei/home/images/{{$data['g_logo']}}" style="height:140px;" alt="">
				    		</div>
				    		<div style="float:left;margin-top:50px;margin-left:20px;">
				    			<input type="hidden" name="g_logo" id="license" value="{{$data['g_logo']}}">
				    			<input id="file_license" name="file_license" type="file" multiple="true">
				    		</div>
							<div>
								<img id="img1" src="" style="height:140px;" alt="">
							</div>	
				    	</div>
				  </div><br>
				  <div style="margin-top:30px;">
				  		<input type="submit" value="确认修改" style="width:100px;height:40px;margin-left:100px;">	
				  </div>
			</form>
		</div>
	</div>
	<script>
		$(function () {
            $("#file_license").change(function () {
                uploadImage();
            });
        });

        //上传图片
        function uploadImage() {
		//判断是否有选择上传文件
            var imgPath = $("#file_license").val();
            if (imgPath == "") {
                alert("请选择上传图片！");
                return;
            }
            //判断上传文件的后缀名
            var strExtension = imgPath.substr(imgPath.lastIndexOf('.') + 1).toLowerCase();
            if (strExtension != 'jpg' && strExtension != 'gif'
                && strExtension != 'png' && strExtension != 'bmp') {
                alert("请选择图片文件");
                return;
            }
            var formData = new FormData();
            formData.append("file_license", $('#file_license')[0].files[0]);
            formData.append("_token", '{{csrf_token()}}');
            $.ajax({
                type: "post",
                url: "/upload/good",
                data: formData,
                async: true,
                cache: false,
                contentType: false,
                processData: false,
                success: function(data) {
                    $('#img1').attr('src','/'+data);
                    $('#license').val(data);

                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert("上传失败，请检查网络后重试");
                }
            });
        }
	</script>
@endsection